<template>
	<view class="content" :style="'background:'+publicTextColor.app_bg_color+';'">
		<view class="topTitle" :style="'top:'+zhuangtai+'px'">
			<image class="back" @click="backClick" :src="publicimg.btn_back" mode=""></image>
			<view class="" style="font-size: 32rpx;">
				我的卡片
			</view>
		</view>
		<view class="cardindex" :style="'margin-top:'+(zhuangtai+52)+'px;background:'+publicTextColor.app_theme_color+';'">
			<view class="font30 titletop" :style="'color:'+publicTextColor.font_1st_color+';border-bottom:2rpx solid '+publicTextColor.app_border_color+';'">
				把万能卡转换为
			</view>
			<view class="cardlist">
				<view class="item" @click="getCardid(item.id,item.image)" v-for="(item, index) in cardlist" :key="index">
					<image class="maskcorner" v-if="cardid == item.id" :src="publicimg.index_card_badge_icon" mode=""></image>
					<view class="info">
						<view v-if="cardid == item.id" class="bordershow" :style="'box-shadow: 0rpx 0rpx 15rpx 12rpx '+publicTextColor.card_selected_border_color+';'"></view>
						<image class="cardimage"  :src="item.image" mode=""></image>
						<text class="font28" :style="'color:'+publicTextColor.font_1st_color+';'">{{item.name}}({{item.member_card}})</text>
					</view>
				</view>
			</view>
			<image class="item-image" :src="item_image" mode=""></image>
			<view class="postbtn" @click="getExchange">
				<image class="bgimgpublic" style="z-index: 0;" :src="publicimg.btn_lg_warm" mode=""></image>
				<text class="font36 fontw500" :style="'z-index:1;color:'+publicTextColor.font_1st_color+';'">确认转换</text>
			</view>
		</view>
		<uni-popup ref="fileInsufficient" type="center">
			<view class="filesynpopup">
				<view class="filetop" :style="'background:'+publicTextColor.app_border_color+';'">
					<image :src="publicimg.btn_close" mode="" @click="closeFilePopup"></image>
					<text class="font30" :style="'color:'+publicTextColor.font_1st_color+';'">提示</text>
				</view>
				<view class="filecenter" :style="'background:'+publicTextColor.app_theme_color+';'">
					<text class="tiptext font30" :style="'color:'+publicTextColor.font_1st_color+';'">抱歉，您的卡片数量不足无法进行转赠！</text>
					<view class="btn" @click="closeFilePopup">
						<image class="bgimgpublic" :src="publicimg.btn_xs_warm" mode=""></image>
						<text class="font30" :style="'z-index:1;color:'+publicTextColor.font_1st_color+';'">确定</text>
					</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	var cssjs = require('@/js/cssjs.js')
	var imagejs = require('@/js/imagejs.js')
	var util = require('@/js/util.js')
	export default {
		data() {
			return {
				zhuangtai:0,
				publicTextColor:'',
				publicimg:imagejs.publicimg,
				cardid:0,
				cardlist:[],
				super_card:'',
				total_card:0,
				item_image:"",
			};
		},
		onShow() {
			this.getList()
			// this.$refs.successCard.open()
			let that = this
			let aniosgaodu = 0
			uni.getSystemInfo({
				success: function(res) {
					console.log(res);
					that.zhuangtai = res.statusBarHeight;
					var a = res.model.split(' ');
					if (a[0] == 'iPhone') {
						aniosgaodu = 44;
					} else {
						aniosgaodu = 48;
					}
					that.zhuangtai = parseInt(that.zhuangtai)+4
					console.log(that.zhuangtai)
				}
			});
		},
		onLoad() {
			this.setcolorConfig()
		},
		methods:{
			getExchange(){
				let _self = this
				uni.request({
					url: util.getUrl("card/super_card_exchange"),
					header: {
						'content-type': 'application/x-www-form-urlencoded',
						'Authori-zation':uni.getStorageSync("token")
					},
					data:{
						card_id: _self.cardid
					},
					method: 'POST',
					success: res => {
						if(res.data.code == 1){
							uni.showToast({
								title:'兑换成功！'
							})
							_self.updateList()
						}
					}
				});
			},
			getList(){
				let _self = this
				uni.request({
					url: util.getUrl("member/card"),
					header: {
						'content-type': 'application/x-www-form-urlencoded',
						'Authori-zation':uni.getStorageSync("token")
					},
					data:{
					},
					method: 'POST',
					success: res => {
						if(res.data.code == 1){
							_self.cardlist = res.data.data.card
							_self.super_card = res.data.data.super_card
							_self.total_card = res.data.data.total_card
							_self.item_image = res.data.data.card[0].image
							_self.cardid = res.data.data.card[0].id
						}
					}
				});
			},
			updateList(){
				let _self = this
				uni.request({
					url: util.getUrl("member/card"),
					header: {
						'content-type': 'application/x-www-form-urlencoded',
						'Authori-zation':uni.getStorageSync("token")
					},
					data:{
					},
					method: 'POST',
					success: res => {
						if(res.data.code == 1){
							_self.cardlist = res.data.data.card
							_self.super_card = res.data.data.super_card
							_self.total_card = res.data.data.total_card
						}
					}
				});
			},
			setcolorConfig(){
				this.publicTextColor =  uni.getStorageSync("diyColor")
				this.publicimg = uni.getStorageSync("diyImg")
			},
			getfriendCard(){
				this.$refs.successCard.close()
			},
			closeFilePopup(){
				this.$refs.fileInsufficient.close()
			},
			giveCard(){
				this.$refs.fileInsufficient.open()
			},
			getCardid(id,image){
				this.item_image = image
				this.cardid = id
			},
			backClick(){
				uni.navigateBack({
					
				})
			}
		}
	}
</script>

<style lang="scss">
	.successsynpopup{
		display: flex;
		justify-content: center;
		align-items: center;
		flex-direction: column;
		width: 690rpx;
		box-sizing: border-box;
		padding-bottom: 47rpx;
		border-radius: 20rpx;
		
		.centercard{
			display: flex;
			align-items: center;
			justify-content: center;
			width: 542rpx;
			height: 543rpx;
			position: relative;
			margin-bottom: 33rpx;
			.bgimg{
				position: absolute;
				width: 123%;
				height: 123%;
			}
			.cardimagegoods{
				width: 261rpx;
				height: 346rpx;
				z-index: 1;
			}
		}
		.cardtypetext{
			margin-bottom: 46rpx;
		}
		.successbtn{
			display: flex;
			align-items: center;
			justify-content: center;
			width: 419rpx;
			height: 88rpx;
			position: relative;
		}
		.successcenter{
			display: flex;
			align-items: center;
			justify-content: center;
			width: 481rpx;
			height: 481rpx;
			position: relative;
			.successgoods{
				position: relative;
				width: 211rpx;
				height: 172rpx;
				.goodsNumber{
					-webkit-text-stroke: 5rpx #8B3703;
					text-stroke: 5rpx #8B3703;
					position: absolute;
					bottom: 0;
					right: 36rpx;
				}
			}
			.bgimg{
				position: absolute;
				width: 100%;
				height: 100%;
				top: 0;
				left: 0;
				z-index: -1;
			}
		}
		.successtop{
			width: 415rpx;
			height: 131rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			position: relative;
			margin-top: -50rpx;
			margin-bottom: 29rpx;
		}
	}
	.filesynpopup{
		display: flex;
		flex-direction: column;
		align-items: center;
		width: 690rpx;
		border-radius: 20rpx;
		.filecenter{
			display: flex;
			flex-direction: column;
			align-items: center;
			width: 100%;
			padding: 80rpx 0 26rpx 0;
			box-sizing: border-box;
			.tiptext{
				margin-bottom: 70rpx;
				text-align: center;
			}
			.btn{
				width: 209rpx;
				height: 68rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				position: relative;
				image{
					z-index: 0;
				}
			}
		}
		.filetop{
			display: flex;
			align-items: center;
			justify-content: center;
			position: relative;
			height: 80rpx;
			width: 100%;
			border-radius: 16rpx 16rpx 0px 0px;
			image{
				position: absolute;
				width: 31rpx;
				height: 31rpx;
				right: 24rpx;
			}
		}
	}
	.cardindex{
		display: flex;
		width: 690rpx;
		padding: 26rpx 0rpx 222rpx 0rpx;
		box-sizing: border-box;
		flex-direction: column;
		border-radius: 20rpx;
		.item-image{
			width: 414rpx;
			height: 544rpx;
			margin: 0 auto;
			padding-bottom: 75rpx;
		}
		.postbtn{
			display: flex;
			align-items: center;
			justify-content: center;
			width: 630rpx;
			height: 80rpx;
			position: relative;
			margin: 0 auto;
		}
		.cardlist{
			display: flex;
			min-height: 249rpx;
			width: 100%;
			flex-wrap: wrap;
			padding-left: 34rpx;
			box-sizing: border-box;
			margin-top: 39rpx;
			margin-bottom: 49rpx;
			.item{
				position: relative;
				display: flex;
				flex-direction: column;
				align-items: center;
				margin-bottom: 46rpx;
				.maskcorner{
					width: 51rpx;
					height: 50rpx;
					position: absolute;
					top: 0;
					left: 0;
				}
				.info{
					display: flex;
					align-items: center;
					flex-direction: column;
					margin-right: 20rpx;
					.bordershow{
						width: 100rpx;
						height: 136rpx;
						background: rgba(23, 220, 238, 0);
						border-radius: 17rpx;
						position: absolute;
						top: 2rpx;
						left: 6rpx;
					}
					.cardimage{
						width: 110rpx;
						height: 144rpx;
					}
				}
			}
		}
		.titletop{
			width: 100%;
			box-sizing: border-box;
			padding-bottom: 26rpx;
			text-align: center;
		}
	}
	.content{
		min-height: 100vh;
		width: 750rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		box-sizing: border-box;
	}
	.topTitle{
		color: #FFFFFF;
		display: flex;
		align-items: center;
		height: 67rpx;
		justify-content: center;
		position: absolute;
		z-index: 10;
		width: 100%;
		.back{
			width: 20rpx;
			height: 31rpx;
			position: absolute;
			left: 31rpx;
		}
	}
</style>
